package com.aaa.controller.api;

import com.aaa.entity.Dept;
import com.aaa.entity.Notice;
import com.aaa.service.NoticeService;
import com.aaa.vo.DeptVo;
import com.aaa.vo.NoticeVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/api/notice")
public class NoticeControllerApi {
    @Autowired
    private NoticeService noticeService;
    //分页查询
    @PostMapping("searchNotice/{currentPage}/{pageSize}")
    public Result<IPage<Notice>> searchNotice(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody NoticeVo noticeVo){
        return noticeService.findByConditions(currentPage, pageSize, noticeVo);
    }

    //添加修改
    @PostMapping("saveAndUpdate")
    public Result saveAndUpdate(Notice notice) {
        if (noticeService.saveAndUpdate(notice)) {
            return new Result(200, "操作成功", true);
        } else {
            return new Result(500, "操作失败", false);
        }
    }
    //删除
    @DeleteMapping("delById/{id}")
    public Result delById(@PathVariable Integer id){
        if (noticeService.delById(id)){
            return new Result(200,"修改成功",true);
        }else {
            return  new Result(500,"修改失败",false);
        }
    }
}
